﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.ModFlow.Domain.DomainLayer;
namespace HA.ModFlow.Controls.Windows
{
    /// <summary>
    /// winPCGSolver.xaml 的交互逻辑
    /// </summary>
    public partial class winPCGSolver : Window
    {
        public winPCGSolver(PCGSolver Pcg)
        {
            InitializeComponent();
            this.PCGsol = (PCGSolver)Pcg.Clone();
            this.RbtnCPCONDM.Click += new RoutedEventHandler(chkCPCONDM_Click);
            this.RbtnCPCONDP.Click += new RoutedEventHandler(chkCPCONDM_Click);

            this.labelHead.DataContext = this;
            this.labelResidual.DataContext = this;
        }

        string _waterHeadLabel="水头变化收敛规则";

        public string WaterHeadLabel
        {
            get { return _waterHeadLabel; }
            set { _waterHeadLabel = value; }
        }

        string _residualLabel = "残差收敛规则";

        public string ResidualLabel
        {
            get { return _residualLabel; }
            set { _residualLabel = value; }
        }

        void chkCPCONDM_Click(object sender, RoutedEventArgs e)
        {
            if (this.RbtnCPCONDM.IsChecked.Value)
            {
                this.PCGsol.CPCOND = 0;
                this.txtRELAX.IsEnabled = true;
                this.cboNBPOL.IsEnabled = false;
            }
            else
            {
                this.txtRELAX.IsEnabled = false;
                this.cboNBPOL.IsEnabled = true;
                this.PCGsol.CPCOND = 1;
            }
        }

        private PCGSolver _PCGsol;

        public PCGSolver PCGsol
        {
            get { return _PCGsol; }
            set { _PCGsol = value; }
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {

            this.DialogResult = true;
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this.PCGsol;
            if (this.PCGsol.CPCOND == 0)
            {
                this.RbtnCPCONDM.IsChecked = true;
            }
            else
            {
                this.RbtnCPCONDP.IsChecked = true;
            }
            chkCPCONDM_Click(sender, e);
            this.cboMUTPCG.SelectedIndex = this.PCGsol.MUTPCG;
            this.cboNBPOL.SelectedIndex = this.PCGsol.NBPOL - 1;
        }

        private void cboMUTPCG_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.PCGsol.MUTPCG = this.cboMUTPCG.SelectedIndex;
        }

        private void cboNBPOL_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.PCGsol.NBPOL = this.cboNBPOL.SelectedIndex + 1;
        }
    }
}
